package easy;

public class Solution_434 {

    public int countSegments(String s) {
        int count = 0;
        boolean flag = true;
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (check(c)) {
                flag = false;
            } else {
                if (!flag) {
                    count++;
                }
                flag = true;
            }
        }
        return flag ? count : ++count;
    }

    private boolean check(char c) {
        if (c==' ') {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_434 model = new Solution_434();
        //        int strings = model.thirdMax(new int[]{2, 2, 3, 1});
        System.out.println(model.countSegments("Hello, my name is John"));
        System.out.println(model.countSegments("love live! mu'sic forever"));
        System.out.println(model.countSegments("The one-hour drama series Westworld is a dark odyssey about the dawn of artificial consciousness and the evolution of sin. Set at the intersection of the near future and the reimagined past, it explores a world in which every human appetite, no matter how noble or depraved, can be indulged."));
        System.out.println(model.countSegments(", , , ,        a, eaefa"));
        System.out.println('-'-0);
    }
}
